package com.treasure.service.listener;

import com.treasure.service.constant.mq.GlobalConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

/**
 * 信用卡办理结果处理
 *
 * @author <a href="mailto:panxinwen@yingu.com">Pan Xinwen</a>
 * @version 1.0 2018-09-22 15:06
 */
@Component
public class CreditCardScheduleListener {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 信用卡申请结果处理
     * @param bytes
     */
    @RabbitListener(queues = "${mq.config.card-dispose-result-queue}", containerFactory = "rabbitListenerContainerFactory")
    public void creditCardScheduleListener(@Payload byte[] bytes) {
        try {
            logger.info(" 接受mq消息，进入【银行卡办理结果通知】");
            String result = null;
            result = new String(bytes, GlobalConstant.ENCODING_UTF8);
            if(result != null ){
                logger.info(" 执行银行卡办理结果通知MQ数据{}", result);
                result = result.replaceAll("returnCode","resultCode");
                result = result.replaceAll("returnMessage","resultMessage");
            }else{
                logger.info(" 执行银行卡办理结果通知MQ数据为空", result);
                return;
            }

        } catch (Exception e) {

            e.printStackTrace();
        }
    }


}
